<template>
  <div class="UpdateBirthday-wrap">
    <van-datetime-picker
      v-model="currentDate"
      type="date"
      @confirm = 'onConfirm'
      @cancel = '$emit("onCancle")'
      title="选择年月日"
      :min-date="minDate"
      :max-date="maxDate"
    />
  </div>
</template>
<script>
import { changeUserProfile } from '../../../api/profile'
import dayjs from 'dayjs'
export default {
  name: 'UpdateBirthday',
  components: {},
  data () {
    return {
      minDate: new Date(1990, 0, 1),
      maxDate: new Date(2025, 10, 1),
      currentDate: new Date(this.value)
    }
  },
  props: {
    value: {
      type: String,
      required: true
    }
  },
  methods: {
    async onConfirm (value) {
      //value 是当前选中的时间
       let currentTime = dayjs(value).format('YYYY-MM-DD')
       let params = {
           birthday:currentTime
       }
       await changeUserProfile(params)//发送请求
       this.$emit('input',currentTime)//传参
       this.$emit('onCancle')//关闭pop
       this.$toast.success('修改成功')
       
    }
  }
}
</script>
<style scoped>
</style>
